package main;

import bean.Task;
import bean.Worker;
import test.exact.Exact;

import java.util.*;

public class TwoLevelFramework {
    public static void main(String[] args) {
        //1. 初始化-数据准备
        //工人数据
        HashSet<String> w1Skills = new HashSet<>();
        w1Skills.add("e1");
        w1Skills.add("e2");
        Worker w1 = new Worker("w1",w1Skills, 2.0,1);

        HashSet<String> w2Skills = new HashSet<>();
        w2Skills.add("e1");
        Worker w2 = new Worker("w2",w2Skills, 1.0,1);

        HashSet<String> w3Skills = new HashSet<>();
        w3Skills.add("e2");
        w3Skills.add("e3");
        Worker w3 = new Worker("w3",w3Skills, 3.0,2);

        HashSet<Worker> workers = new HashSet<>();
        workers.add(w1);
        workers.add(w2);
        workers.add(w3);

        //任务数据
        HashSet<String> taskSkills = new HashSet<>();
        taskSkills.add("e1");
        taskSkills.add("e2");
        taskSkills.add("e3");
        Task task = new Task(taskSkills);

        //k值设置为2
        int k = 2;

        HashSet<Worker> team = new HashSet<>();
        //top-1 贪心算法
        //team = Greedy.greedy(workers,task);
        //top-1 exact算法
        team = Exact.exact(workers,task);






        //初始化 queue（Queue）、group（G）
        Queue<HashSet<Worker>> queue = new LinkedList<>();
        ArrayList<HashSet<Worker>> groups = new ArrayList<>();

        //算法第二行，把top-1算法的返回team插入队列
        //add()和remove()方法在失败的时候会抛出异常(不推荐)
        queue.offer(team);

        //开始第三行while循环
        while ( !queue.isEmpty() ) {
            HashSet<Worker> res = new HashSet<>();
            res = queue.element();
            groups.add(res);
            if (groups.size() == k) {
                //return groups;
                //此时就直接打印groups里的团队
                break;
            }
            queue.poll();

            Iterator<Worker> iteratorRes = res.iterator();
            while ( iteratorRes.hasNext() ) {
                HashSet<Worker> workersRes = new HashSet<>();
                Iterator<Worker> iteratorWorkers = workers.iterator();
                while ( iteratorWorkers.hasNext() ) {
                    workersRes.add(iteratorWorkers.next());
                }
                workersRes.remove(iteratorRes.next());
                queue.offer(Greedy.greedy(workersRes,task));
            }
        }

    }
}
